package cn.netjava.personblogaction;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.netjava.actioninterface.Action;
import cn.netjava.dao.ReviewDao;
import cn.netjava.pojo.User;
/**
 * this action to use for dealing with writing review ;
 * the show the review to the article page 
 * @author Administrator
 *
 */
public class WriteReviewAction implements Action{

	public String excute(HttpServletRequest request,
			HttpServletResponse response) {
		
			/*get the user which has logined*/
			HttpSession session =request.getSession();
			User user =(User)session.getAttribute("loginUser");
			
			if(null!=user){
					/*get this article*/
					int articalID =Integer.parseInt(request.getParameter("articleid"));
					/*obtain the user's review*/
					String reviewContent = request.getParameter("REVIEW");
					System.out.println("reviewContent:"+reviewContent+"-------uid:"+user.getId());
					/*get a ReviewDao object and put this review to mysql */
					ReviewDao rdao =ReviewDao.getReviewDao();
					rdao.addReview(articalID, reviewContent, user.getId());
					
					return "showonearticle.cn";
			}			
		
		return "/JSP/notlogin.html";
	}

}
